package com.lingnan.wanxiangxinxun.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;


@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory, ObjectMapper om) {
//        RedisTemplate<String, Object> template = new RedisTemplate<>();
        RedisTemplate template = new RedisTemplate<>();

        template.setConnectionFactory(factory); //设置redis的连接工厂对象

        template.setKeySerializer(new StringRedisSerializer()); // 设置redis key的序列化器
        template.setHashKeySerializer(new StringRedisSerializer());

//        template.setValueSerializer(new GenericJackson2JsonRedisSerializer(om)); // 设置redis value的序列化器
//        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer(om));

        return template;
    }
}